package cate.game.play.skill.passive.hero;

import cate.common.util.XT;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.skill.FighterCD;
import cate.game.play.skill.passive.PassiveHandler;

import java.util.List;

/**
 * 生命值低于50%时，为自身附加一个自身攻击力280%的【护盾】，持续3回合；此外，还为全体友方提供【抗控强化】
 */
public class 狂沙守护PH extends PassiveHandler {

	private int 检测血量;

	private int 自身buff;

	private List<Integer> 全体buff;

	private int 冷却回合;

	//检测血量=5000&自身buff=？？&全体buff=？？冷却回合=99
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		检测血量 = args.getInt("检测血量", 0);
		自身buff = args.getInt("自身buff", 0);
		全体buff = args.getIntList("全体buff");
		冷却回合 = args.getInt("冷却回合", 99);
	}

	@Override
	public void parseExt(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		全体buff = XT.merge(全体buff, args.getIntList("全体buff"));
		冷却回合 += args.getInt("冷却回合", 0);
	}

	private int lastAddRound;

	@Override
	public void onMoveDone(MoveCtx move, TimeActionCtx action) {
		if (FighterCD.inCD(lastAddRound, 冷却回合, move.getRound().index)) {
			return;
		}
		if (skill.owner.attr.total().hpCurRate() > 检测血量) {
			return;
		}
		lastAddRound = action.getRound().index;
		skill.owner.buff.tryAddByTid(action, 自身buff);
		if (XT.isNotBlank(全体buff)) {
			for (Integer buff : 全体buff) {
				skill.owner.getFightTeam().getFightersAlive().forEach(f -> f.buff.tryAddByTid(action, skill.owner, buff));
			}
		}
	}
}
